package com.ynt.pay.mock.controller;

import com.ynt.pay.mock.service.TraceIdService;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * Skywalking TraceId测试
 *
 * @Author: ganbo
 * @Date: 2021/1/20 20:31
 */

@RestController
@Slf4j
public class SkyWalkingTraceIdController {

    @Autowired
    TraceIdService traceIdService;

    @GetMapping("traceId")
    public String traceIdTest() {

        //设置值
        TraceContext.putCorrelation("skname", "甘波");

        //获取刚才设置的值
        Optional<String> skname = TraceContext.getCorrelation("skname");
        System.out.println(skname.get());


        String traceId1 = TraceContext.traceId();
        String traceId2 = TraceContext.traceId();

        log.info("traceId1====>{}", traceId1);
        log.info("traceId2====>{}", traceId2);


        traceIdService.testTranceAnnotation();
        return "SUCCESS";
    }


}
